package com.highspeed.bdk.bean.entity.physical;

import com.bianmaba.spring.data.jpa.domain.annotations.QueryCacheable;
import com.highspeed.bdk.bean.base.IncrementEntity;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by chenjiabin on 2018/3/23.
 */
@Entity
@DynamicUpdate(true)
@DynamicInsert(true)
@QueryCacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Cpu extends IncrementEntity {
    // CPUID="12808" MachineBoxNo="0" SlotNo="2" BoardName="SC" BoardType="2" CPUModel="0" CPUSerial="0" CPUType="3" CPUVersion="0" CPUNetID="0"

    @Column(nullable = false, length = 32)
    private String cpuId;

    @Column(length = 64)
    private String cpuName;

    @Column(length = 32)
    private String slotNo;


    @Column(length = 32)
    private Integer cpuModel;

    @Column(length = 32)
    private String cpuSerial;

    @Column(length = 32)
    private Integer cpuType;

    @Column(length = 32)
    private String cpuVersion;

    @Column(length = 32)
    private String cpuNetID;

    @ManyToOne(optional = false)
    @JoinColumn(name = "Board_id", nullable = false)
    private Board board;
    /**
     * 此映射无GET及SET函数，只用于维护关系用（在对应CPU被移除时可以自动移除链路）
     */
    @OneToMany(orphanRemoval = true, cascade = CascadeType.ALL, mappedBy = "leftCpu")
    private List<PhysicalLink> rightLinks = new ArrayList<PhysicalLink>(0);

    /**
     * 此映射无GET及SET函数，只用于维护关系用（在对应CPU被移除时可以自动移除链路）
     */
    @OneToMany(orphanRemoval = true, cascade = CascadeType.ALL, mappedBy = "rightCpu")
    private List<PhysicalLink> leftLinks = new ArrayList<PhysicalLink>(0);

    public String getCpuId() {
        return cpuId;
    }

    public void setCpuId(String cpuId) {
        this.cpuId = cpuId;
    }

    public String getMachineBoxNo() {
        if (board != null) {
            return board.getMachineBoxNo();
        } else {
            return null;
        }
    }


    public String getSlotNo() {
        return slotNo;
    }

    public void setSlotNo(String slotNo) {
        this.slotNo = slotNo;
    }

    public String getBoardName() {
        if (board != null) {
            return board.getBoardName();
        } else {
            return null;
        }
    }

    public Integer getBoardType() {
        if (board != null) {
            return board.getBoardType();
        } else {
            return null;
        }
    }

    public Integer getCpuModel() {
        return cpuModel;
    }

    public void setCpuModel(Integer cpuModel) {
        this.cpuModel = cpuModel;
    }

    public String getCpuSerial() {
        return cpuSerial;
    }

    public void setCpuSerial(String cpuSerial) {
        this.cpuSerial = cpuSerial;
    }

    public Integer getCpuType() {
        return cpuType;
    }

    public void setCpuType(Integer cpuType) {
        this.cpuType = cpuType;
    }

    public String getCpuVersion() {
        return cpuVersion;
    }

    public void setCpuVersion(String cpuVersion) {
        this.cpuVersion = cpuVersion;
    }

    public String getCpuNetID() {
        return cpuNetID;
    }

    public void setCpuNetID(String cpuNetID) {
        this.cpuNetID = cpuNetID;
    }

    public Board getBoard() {
        return board;
    }

    public void setBoard(Board board) {
        this.board = board;
    }

    public String getCpuName() {
        return cpuName;
    }

    public void setCpuName(String cpuName) {
        this.cpuName = cpuName;
    }
}
